/**
 * 
 */
package com.sig.sigandroidDisconnected;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;

import javax.microedition.khronos.opengles.GL10;

import android.opengl.GLES20;

/**
 * @author zou
 *
 */
public class TriangleImplemRender extends ES20AbstractRenderer {

	//A raw native buffer to hold the point coordinates
	private FloatBuffer mFVertexBuffer;
	private static final int FLOAT_SIZE_BYTES = 4;
	private final float[] mTriangleVerticesData = {
			// X, Y, Z
			-47.0f, -0.5f, 0,
			47.53358f, -0.5f, 0,
			47.124111f, 1.11803399f, 0 };

	public TriangleImplemRender()
	{
		ByteBuffer vbb = ByteBuffer.allocateDirect(mTriangleVerticesData.length
				* FLOAT_SIZE_BYTES);
		vbb.order(ByteOrder.nativeOrder());
		mFVertexBuffer = vbb.asFloatBuffer();
		mFVertexBuffer.put(mTriangleVerticesData);
		mFVertexBuffer.position(0);
		
		//this.setupMatrices();
		//this.translate(0f, -1f, 0);
		
		//this.setupMatrices();
		//this.rotate(45, 1f, 0f, 1f);
		
		
	}


	/* (non-Javadoc)
	 * @see com.sig.sigandroid.ES20AbstractRenderer#draw(javax.microedition.khronos.opengles.GL10, int)
	 */
	@Override
	protected void draw(GL10 gl, int positionHandle) {
		GLES20.glVertexAttribPointer(positionHandle, 3, GLES20.GL_FLOAT, false,
				0, mFVertexBuffer);
		checkGlError("glVertexAttribPointer maPosition");
		GLES20.glEnableVertexAttribArray(positionHandle);
		checkGlError("glEnableVertexAttribArray maPositionHandle");
		this.setupMatrices();
		GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 3);
		checkGlError("glDrawArrays");
		
	}

}
